#include "Gun.h"


CGun::CGun()
{
}

CGun::CGun(LPD3DXSPRITE SpriteHandler, LPWSTR Path, double Width, double Height, int Count, int SpritePerRow, D3DCOLOR TransparentColor)
{
	_sprite = new CSprite(SpriteHandler, Path, Width, Height, Count, SpritePerRow, TransparentColor);
	_gun = false;
}

void CGun::Add(CBullet *ibullet)
{
	ix0 = ibullet->_x;
	iy0 = ibullet->_y;
	_listBullet.push_back(ibullet);//new CBullet(ibullet)
}

void CGun::CheckALiveBullet()
{
	//int i = 1;		//_listBullet: element begin is 1
	list<CBullet>::iterator ibullet = _listBullet.begin();

	while (_listBullet.size() > 0 && ((*ibullet).CheckALive() == false))
	{
		_listBullet.remove(*ibullet);
		ibullet = _listBullet.begin();
	}
}

void CGun::Draw(CSprite *isprite)
{
	CheckALiveBullet();

	if (_listBullet.size() > 0)
	{
		list<CBullet>::iterator ibullet = _listBullet.begin();

		for (ibullet; ibullet != _listBullet.end(); ibullet++)
		{
			if ((*ibullet).CheckALive())
			{
				(*ibullet).Update();
				(*ibullet).Draw(isprite);
			}
		}
	}
}
void CGun::Draw()
{
	CheckALiveBullet();

	if (_listBullet.size() > 0)
	{
		list<CBullet>::iterator ibullet = _listBullet.begin();

		for (ibullet; ibullet != _listBullet.end(); ibullet++)
		{
			if ((*ibullet).CheckALive())
			{
				(*ibullet).Update();
				(*ibullet).Draw(_sprite);
			}
		}
	}
}

CGun::~CGun()
{
}